package edu.upf.grupE.Entities;

/*
 * This class was automatically generated with 
 * <a href="http://www.castor.org">Castor 1.1.2.1</a>, using an XML
 * Schema.
 * $Id$
 */

  //---------------------------------/
 //- Imported classes and packages -/
//---------------------------------/

import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.Unmarshaller;

/**
 * Class Pnews.
 * 
 * @version $Revision$ $Date$
 */
public class Pnews implements java.io.Serializable {


      //--------------------------/
     //- Class/Member Variables -/
    //--------------------------/

    /**
     * Field _id.
     */
    private long _id;

    /**
     * keeps track of state for field: _id
     */
    private boolean _has_id;

    /**
     * Field _title.
     */
    private java.lang.String _title;

    /**
     * Field _contentUnitList.
     */
    private java.util.List _contentUnitList;


      //----------------/
     //- Constructors -/
    //----------------/

    public Pnews() {
        super();
        this._contentUnitList = new java.util.ArrayList();
    }


      //-----------/
     //- Methods -/
    //-----------/

    /**
     * 
     * 
     * @param vContentUnit
     * @throws java.lang.IndexOutOfBoundsException if the index
     * given is outside the bounds of the collection
     */
    public void addContentUnit(
            final ContentUnit vContentUnit)
    throws java.lang.IndexOutOfBoundsException {
        this._contentUnitList.add(vContentUnit);
    }

    /**
     * 
     * 
     * @param index
     * @param vContentUnit
     * @throws java.lang.IndexOutOfBoundsException if the index
     * given is outside the bounds of the collection
     */
    public void addContentUnit(
            final int index,
            final ContentUnit vContentUnit)
    throws java.lang.IndexOutOfBoundsException {
        this._contentUnitList.add(index, vContentUnit);
    }

    /**
     */
    public void deleteId(
    ) {
        this._has_id= false;
    }

    /**
     * Method enumerateContentUnit.
     * 
     * @return an Enumeration over all possible elements of this
     * collection
     */
    public java.util.Enumeration enumerateContentUnit(
    ) {
        return java.util.Collections.enumeration(this._contentUnitList);
    }

    /**
     * Method getContentUnit.
     * 
     * @param index
     * @throws java.lang.IndexOutOfBoundsException if the index
     * given is outside the bounds of the collection
     * @return the value of the ContentUnit at the given index
     */
    public ContentUnit getContentUnit(
            final int index)
    throws java.lang.IndexOutOfBoundsException {
        // check bounds for index
        if (index < 0 || index >= this._contentUnitList.size()) {
            throw new IndexOutOfBoundsException("getContentUnit: Index value '" + index + "' not in range [0.." + (this._contentUnitList.size() - 1) + "]");
        }
        
        return (ContentUnit) _contentUnitList.get(index);
    }

    /**
     * Method getContentUnit.Returns the contents of the collection
     * in an Array.  <p>Note:  Just in case the collection contents
     * are changing in another thread, we pass a 0-length Array of
     * the correct type into the API call.  This way we <i>know</i>
     * that the Array returned is of exactly the correct length.
     * 
     * @return this collection as an Array
     */
    public ContentUnit[] getContentUnit(
    ) {
        ContentUnit[] array = new ContentUnit[0];
        return (ContentUnit[]) this._contentUnitList.toArray(array);
    }

    /**
     * Method getContentUnitCount.
     * 
     * @return the size of this collection
     */
    public int getContentUnitCount(
    ) {
        return this._contentUnitList.size();
    }

    /**
     * Returns the value of field 'id'.
     * 
     * @return the value of field 'Id'.
     */
    public long getId(
    ) {
        return this._id;
    }

    /**
     * Returns the value of field 'title'.
     * 
     * @return the value of field 'Title'.
     */
    public java.lang.String getTitle(
    ) {
        return this._title;
    }

    /**
     * Method hasId.
     * 
     * @return true if at least one Id has been added
     */
    public boolean hasId(
    ) {
        return this._has_id;
    }

    /**
     * Method isValid.
     * 
     * @return true if this object is valid according to the schema
     */
    public boolean isValid(
    ) {
        try {
            validate();
        } catch (org.exolab.castor.xml.ValidationException vex) {
            return false;
        }
        return true;
    }

    /**
     * Method iterateContentUnit.
     * 
     * @return an Iterator over all possible elements in this
     * collection
     */
    public java.util.Iterator iterateContentUnit(
    ) {
        return this._contentUnitList.iterator();
    }

    /**
     * 
     * 
     * @param out
     * @throws org.exolab.castor.xml.MarshalException if object is
     * null or if any SAXException is thrown during marshaling
     * @throws org.exolab.castor.xml.ValidationException if this
     * object is an invalid instance according to the schema
     */
    public void marshal(
            final java.io.Writer out)
    throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        Marshaller.marshal(this, out);
    }

    /**
     * 
     * 
     * @param handler
     * @throws java.io.IOException if an IOException occurs during
     * marshaling
     * @throws org.exolab.castor.xml.ValidationException if this
     * object is an invalid instance according to the schema
     * @throws org.exolab.castor.xml.MarshalException if object is
     * null or if any SAXException is thrown during marshaling
     */
    public void marshal(
            final org.xml.sax.ContentHandler handler)
    throws java.io.IOException, org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        Marshaller.marshal(this, handler);
    }

    /**
     */
    public void removeAllContentUnit(
    ) {
        this._contentUnitList.clear();
    }

    /**
     * Method removeContentUnit.
     * 
     * @param vContentUnit
     * @return true if the object was removed from the collection.
     */
    public boolean removeContentUnit(
            final ContentUnit vContentUnit) {
        boolean removed = _contentUnitList.remove(vContentUnit);
        return removed;
    }

    /**
     * Method removeContentUnitAt.
     * 
     * @param index
     * @return the element removed from the collection
     */
    public ContentUnit removeContentUnitAt(
            final int index) {
        java.lang.Object obj = this._contentUnitList.remove(index);
        return (ContentUnit) obj;
    }

    /**
     * 
     * 
     * @param index
     * @param vContentUnit
     * @throws java.lang.IndexOutOfBoundsException if the index
     * given is outside the bounds of the collection
     */
    public void setContentUnit(
            final int index,
            final ContentUnit vContentUnit)
    throws java.lang.IndexOutOfBoundsException {
        // check bounds for index
        if (index < 0 || index >= this._contentUnitList.size()) {
            throw new IndexOutOfBoundsException("setContentUnit: Index value '" + index + "' not in range [0.." + (this._contentUnitList.size() - 1) + "]");
        }
        
        this._contentUnitList.set(index, vContentUnit);
    }

    /**
     * 
     * 
     * @param vContentUnitArray
     */
    public void setContentUnit(
            final ContentUnit[] vContentUnitArray) {
        //-- copy array
        _contentUnitList.clear();
        
        for (int i = 0; i < vContentUnitArray.length; i++) {
                this._contentUnitList.add(vContentUnitArray[i]);
        }
    }

    /**
     * Sets the value of field 'id'.
     * 
     * @param id the value of field 'id'.
     */
    public void setId(
            final long id) {
        this._id = id;
        this._has_id = true;
    }

    /**
     * Sets the value of field 'title'.
     * 
     * @param title the value of field 'title'.
     */
    public void setTitle(
            final java.lang.String title) {
        this._title = title;
    }

    /**
     * Method unmarshal.
     * 
     * @param reader
     * @throws org.exolab.castor.xml.MarshalException if object is
     * null or if any SAXException is thrown during marshaling
     * @throws org.exolab.castor.xml.ValidationException if this
     * object is an invalid instance according to the schema
     * @return the unmarshaled Pnews
     */
    public static Pnews unmarshal(
            final java.io.Reader reader)
    throws org.exolab.castor.xml.MarshalException, org.exolab.castor.xml.ValidationException {
        return (Pnews) Unmarshaller.unmarshal(Pnews.class, reader);
    }

    /**
     * 
     * 
     * @throws org.exolab.castor.xml.ValidationException if this
     * object is an invalid instance according to the schema
     */
    public void validate(
    )
    throws org.exolab.castor.xml.ValidationException {
        org.exolab.castor.xml.Validator validator = new org.exolab.castor.xml.Validator();
        validator.validate(this);
    }

}
